home *** CD-ROM | disk | FTP | other *** search
- /* ----------------------------------------------------------------------
-
- CRCValue XFCN
- version 1.0.2
-
- Written by: Paul Celestin
-
- Copyright © 1993-1996 Celestin Company, Inc.
-
- This XFCN returns a 16 bit CRC of a specific piece of text.
-
- Requires one parameter: source text.
-
- 931204 - 1.0.0 - initial release
- 951215 - 1.0.1 - updated for CW7
- 960704 - 1.0.2 - updated for CW9
-
- ---------------------------------------------------------------------- */
-
- #include <A4Stuff.h>
- #include <HyperXCmd.h>
-
- #define PARAMETER_NUMS 1
- #define PARAMETER_TEXT "\pRequires one parameter: source text."
- #define BYTEMASK 0xFF
- #define CRC_CONSTANT 0x1021
- #define WORDMASK 0xFFFF
- #define WORDBIT 0x10000
-
-
- /* ----------------------------------------------------------------------
- prototypes
- ---------------------------------------------------------------------- */
- void DoIt(XCmdPtr paramPtr);
- void CalcCRC(unsigned short v);
-
-
- /* ----------------------------------------------------------------------
- globals
- ---------------------------------------------------------------------- */
-
- unsigned short CRC = 0;
-
-
- /* ----------------------------------------------------------------------
- main
- ---------------------------------------------------------------------- */
- pascal void main(XCmdPtr paramPtr)
- {
- Str255 copyright = "\pCopyright © 1993-1996 Celestin Company, Inc.";
- long oldA4 = SetCurrentA4();
- if (paramPtr->paramCount != PARAMETER_NUMS)
- {
- paramPtr->returnValue =
- PasToZero(paramPtr,PARAMETER_TEXT);
- }
- else
- {
- DoIt( paramPtr );
- }
- SetA4(oldA4);
- }
-
- /* ----------------------------------------------------------------------
- DoIt
- ---------------------------------------------------------------------- */
- void DoIt(XCmdPtr paramPtr)
- {
- char *p;
- Str255 myString;
-
- MoveHHi(paramPtr->params[0]);
- p = *(paramPtr->params[0]);
- while (*p)
- {
- CalcCRC(*p++);
- }
- NumToStr(paramPtr,CRC,myString);
- paramPtr->returnValue = PasToZero(paramPtr,myString);
-
- }
-
-
- /* ----------------------------------------------------------------------
- CalcCRC
- ---------------------------------------------------------------------- */
- void CalcCRC(unsigned short v)
- {
- register int i;
- register unsigned short temp = CRC;
-
- for (i = 0; i < 8; i++)
- {
- v <<= 1;
- if ((temp <<= 1) & WORDBIT)
- temp = (temp & WORDMASK) ^ CRC_CONSTANT;
- temp ^= (v >> 8);
- v &= BYTEMASK;
- }
- CRC = temp;
- }
-